define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    if(Config.account_id == '' || Config.account_id == null){
        Config.account_id = 0;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionrecharge/index/?account_id=' + Config.account_id,
                    add_url: 'feditionrecharge/add',
                    edit_url: 'feditionrecharge/edit',
                    del_url: 'feditionrecharge/del',
                    multi_url: 'feditionrecharge/multi',
                    import_url: 'feditionrecharge/import',
                    table: 'fedition_recharge',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'account_id', title: __('Account_id'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccount/index' data-field='number'"},
                        {field: 'account_name', title: __('Account_id'), operate: false},
                        {field: 'moneytype', title: __('Moneytype'),visible: false,addClass: "selectpage", extend: "data-source='feditionmoneytype/index' data-field='name'"},
                        {field: 'moneytype_name', title: __('Moneytype'), operate: false},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                $("#zeuro").text(data.Statistics.zeuro);
                $("#zpound").text(data.Statistics.zpound);
                $("#zdollar").text(data.Statistics.zdollar);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                require(['selectpage'], function (SelectPage) {
                    var _displayResults = $.fn.selectPage.Constructor.prototype.displayResults;
                    $.fn.selectPage.Constructor.prototype.displayResults = function (self, json, is_query) {
                        _displayResults.call(this, self, json, is_query);
                        if (self.elem.hidden.is("#c-account_id")) {
                            console.log(1);
                            $(self.elem.results[0]).append("<p class='text-center' style='margin:5px;'><a class='btn btn-xs btn-info btn-dialog' title='新增所属账户' data-window='top' href='feditionaccount/add'>新增所属账户</a></p><p style='margin:5px;'>（新增所属账户后需要取消下拉框，重新选择）</p>");
                        }
                        if (self.elem.hidden.is("#c-moneytype")) {
                            $(self.elem.results[0]).append("<p class='text-center' style='margin:5px;'><a class='btn btn-xs btn-info btn-dialog' title='新增金额类型' data-window='top' href='feditionmoneytype/add'>新增金额类型</a></p><p style='margin:5px;'>（新增金额类型后需要取消下拉框，重新选择）</p>");
                        }
                    };
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});